<template>
  <div class="setting-main">
    <div style="margin: 0 auto;display: flex;">
      <div class="left">
        <div
          class="item"
          :class="{ active: choiceItem === 'theme' }"
          @click="choiceMenuFun('theme')"
        >
          <img src="../assets/icon/setting/theme.png" />
          <span>主题</span>
        </div>
        <div
          class="item"
          :class="{ active: choiceItem === 'about' }"
          @click="choiceMenuFun('about')"
        >
          <img src="../assets/icon/setting/about.png" />
          <span>关于</span>
        </div>
      </div>
      <div class="right">
        <router-view />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  name: "Setting",
  data() {
    return {
      choiceItem: "theme"
    };
  },
  watch: {
    // 利用watch方法检测路由变化：
    $route: function(to, from) {
      if (to.fullPath === "/setting/account") {
        var url = "/setting/" + this.choiceItem;
        this.$router.push(url).catch(err => {
          err;
        });
      }
    }
  },
  methods: {
    choiceMenuFun(menu) {
      this.choiceItem = menu;
      var url = "/setting/" + menu;
      this.$router.push(url).catch(err => {
        err;
      });
    }
  },
  mounted() {}
};
</script>

<style lang="less">
* {
  transition: all 0.1s linear;
}

.setting-main {
  color: #7f8c8d;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  display: flex;
  padding: 10px;
  box-sizing: border-box;

  .left {
    padding-right: 10px;
    padding-top: 20px;
    padding-bottom: 20px;
    box-sizing: border-box;
    width: 300px;
    height: 100%;
    border-right: 1px rgba(200, 200, 200, 0.5) solid;

    .item {
      margin-bottom: 10px;
      color: #7f8c8d;
      cursor: pointer;
      display: flex;
      padding: 10px;

      img {
        height: 1.2rem;
      }

      span {
        margin-left: 10px;
        line-height: 1.4rem;
      }
    }

    .item:hover,
    .item.active {
      color: #2980b9;
      border-radius: 10px;
      background: rgba(255, 255, 255, 0.6);
      line-height: 1.4rem;

      img {
        height: 1.4rem;
      }
    }
  }

  .right {
    box-sizing: border-box;
    height: 100%;
    width: 400px;
    padding-left: 10px;
    padding-top: 20px;
    padding-bottom: 20px;
  }
}

.setting-main:hover {
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.2);
}
</style>
